import request from '@src/utils/request';
import { URL } from '@src/configs/constant';

// 查看链列表
export async function getChainList(params) {
  const { Offset = 0, Limit = 10, ChainId = '' } = params;
  let { StartTime = 0, EndTime = 0 } = params;
  if (Number.isNaN(StartTime)) {
    StartTime = 0;
  }
  if (Number.isNaN(EndTime)) {
    EndTime = 0;
  }
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetChainList',
      ChainId,
      StartTime,
      EndTime,
      Offset,
      Limit,
    },
  });
  return res;
}

// 查看区块列表
export async function getBlockList(params) {
  const { Offset = 0, Limit = 10, ChainId = '', BlockHash = '' } = params;
  let { StartTime = 0, EndTime = 0 } = params;
  if (Number.isNaN(StartTime)) {
    StartTime = 0;
  }
  if (Number.isNaN(EndTime)) {
    EndTime = 0;
  }
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetBlockList',
      ChainId,
      BlockHash,
      StartTime,
      EndTime,
      Offset,
      Limit,
    },
  });
  return res;
}
